//package com.ymatou.paymentproxy.testcase;
//
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.List;
//
//import org.junit.After;
//import org.junit.AfterClass;
//import org.junit.Before;
//import org.junit.BeforeClass;
//import org.junit.Test;
//import org.junit.experimental.categories.Category;
//
//import com.ymatou.paymentproxy.parameter.AcquireOrderBean;
//import com.ymatou.paymentproxy.parameter.FastRefundBean;
//import com.ymatou.paymentproxy.service.FastRefundCall;
//import com.ymt.core.tool.Logger;
//import com.ymt.utils.annotation.TestCase;
//import com.ymt.utils.annotation.TestSuite;
//import com.ymt.utils.tag.P1;
//import com.ymt.utils.tag.P2;
//import com.ymt.utils.tag.P3;
//import com.ymttest.business.service.PaymentProxyCallService;
//import com.ymttest.database.model.PPCompensateProcessInfo;
//import com.ymttest.database.model.PPPayment;
//import com.ymttest.database.model.RefundRequest;
//import com.ymttest.database.sqlwapper.PaymentDefaultWapper;
//import com.ymttest.utils.TestDataManager;
//
///**
// * 快速退款接口
// * FreeMaker Template自动生成代码
// */
//@TestSuite
//public class Ts_FastRefund {
//    private static FastRefundBean fastrefundBean;
//    private static FastRefundCall fastrefundCall;
//
//    @BeforeClass
//    public static void setUp() {
//        Logger.createResultFile("快速退款接口");
//    }
//
//    @Before
//    public void caseUp() {
//        fastrefundBean = new FastRefundBean();
//        fastrefundCall = new FastRefundCall();
//    }
//
//    @AfterClass
//    public static void tearDown() {
//        Logger.generateResult(fastrefundCall.getOpurl());
//    }
//
//    @After
//    public void caseDown() {
//        Logger.end();
//    }
//
//    @Test
//    @Category({P1.class})
//    @TestCase
//    public void Tc_FastRefund_001() {
//        Logger.start(true, "快速退款成功");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("0", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("操作成功！", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//
//            verifyDB(aqb, fastrefundBean, fastrefundCall);
//
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P3.class})
//    @TestCase
//    public void Tc_FastRefund_002() {
//        Logger.start(true, "不输入PaymentId提交退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            // fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("1000", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("参数异常", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P3.class})
//    @TestCase
//    public void Tc_FastRefund_003() {
//        Logger.start(true, "不输入TradingId提交退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            // fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("1000", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("参数异常", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P3.class})
//    @TestCase
//    public void Tc_FastRefund_004() {
//        Logger.start(true, "不输入TradeType提交退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            // fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("1000", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("参数异常", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P3.class})
//    @TestCase
//    public void Tc_FastRefund_005() {
//        Logger.start(true, "不输入OrderIdList提交退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            // List<String> OrderIdList=new ArrayList<String>();
//            // OrderIdList.add(TestDataManager.getRandomNum(9));
//            // fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("1000", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("参数异常", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P3.class})
//    @TestCase
//    public void Tc_FastRefund_006() {
//        Logger.start(true, "不输入AppId提交退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            // fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("1000", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("参数异常", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P3.class})
//    @TestCase
//    public void Tc_FastRefund_007() {
//        Logger.start(true, "不输入TraceId提交退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            // fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-",
//            // ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("1000", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("参数异常", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P2.class})
//    @TestCase
//    public void Tc_FastRefund_008() {
//        Logger.start(true, "PaymentId不存在提交退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId("123");
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("1001", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("支付单号不存在", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P2.class})
//    @TestCase
//    public void Tc_FastRefund_009() {
//        Logger.start(true, "PaymentId和TradingId不一致提交退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId() + 1);
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("1002", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("支付单号和交易号不一致", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P2.class})
//    @TestCase
//    public void Tc_FastRefund_010() {
//        Logger.start(true, "支付单连续退款2次退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            fastrefundCall.callService();
//            Logger.verifyEquals("9999", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyIsContains("不能在对象“dbo.RefundRequest”中插入重复键", fastrefundCall.getString("ErrorMessage"),
//                    "验证ErrorMessage");
//
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    @Test
//    @Category({P2.class})
//    @TestCase
//    public void Tc_FastRefund_011() {
//        Logger.start(true, "支付单号和交易号不一致退款失败");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//
//            AcquireOrderBean aqb2 = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb2);
//            PaymentProxyCallService.notifyCall(aqb2);
//            String pid2 = PaymentProxyCallService.getPaymentId(aqb2);
//
//
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid2);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            fastrefundCall.callService();
//            Logger.verifyEquals("1002", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("支付单号和交易号不一致", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    /**
//     * 目前不支持多笔退款，
//     * 现在多笔退款时RefundRequest只记录第一个OrderId
//     * 等重构后再重构这个用例
//     */
//    @Test
//    @Category({P1.class})
//    @TestCase
//    public void Tc_FastRefund_012() {
//        Logger.start(true, "多个订单快速退款成功");
//        try {
//            AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//            PaymentProxyCallService.acquireOrder(aqb);
//            PaymentProxyCallService.notifyCall(aqb);
//            String pid = PaymentProxyCallService.getPaymentId(aqb);
//            fastrefundBean.setAppId("AutoTest");
//            // 这个是支付那里的订单号 目前随便填写
//            List<String> OrderIdList = new ArrayList<String>();
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            OrderIdList.add(TestDataManager.getRandomNum(9));
//            fastrefundBean.setOrderIdList(OrderIdList);
//            fastrefundBean.setTraceId(TestDataManager.getRandomUUID().toString().replace("-", ""));
//            fastrefundBean.setTradeType(1);
//            fastrefundBean.setTradingId(aqb.getOrderId());
//            fastrefundBean.setPaymentId(pid);
//            fastrefundCall.setData(fastrefundBean);
//            fastrefundCall.callService();
//            Logger.verifyEquals("0", fastrefundCall.getString("ErrorCode"), "验证ErrorCode");
//            Logger.verifyEquals("操作成功！", fastrefundCall.getString("ErrorMessage"), "验证ErrorMessage");
//
//            verifyDB(aqb, fastrefundBean, fastrefundCall);
//        } catch (Exception e) {
//            Logger.fail(e);
//        }
//    }
//
//    private void verifyDB(AcquireOrderBean aqb, FastRefundBean fastrefundBean, FastRefundCall fastrefundCall)
//            throws InterruptedException {
//        String paymentId = fastrefundBean.getPaymentId();
//        String orderId = fastrefundBean.getOrderIdList().get(0);
//
//        Logger.comment("验证数据表PP_Payment");
//        PPPayment ppPayment = new PaymentDefaultWapper().selectPPPaymentByPaymentId(paymentId).get(0);
//        Logger.verifyEquals(0, ppPayment.getPayPrice().compareTo(new BigDecimal(aqb.getPayPrice())),
//                "验证PP_Payment表中PayPrice字段");
//        // 回调后才会变成2：退款
//        Logger.verifyEquals(1, ppPayment.getPayStatus(), "验证PP_Payment表中PayStatus字段");
//
//        Logger.comment("验证数据表RefundRequest");
//        RefundRequest RefundRequest = new PaymentDefaultWapper().selectRefundRequestByOrderid(orderId).get(0);
//        Logger.verifyEquals(paymentId, RefundRequest.getPaymentId(), "验证RefundRequest表中PaymentId字段与返回一致");
//        // Logger.verifyEquals(1, RefundRequest.getTradeNo(), "验证RefundRequest表中TradeNo字段");
//        Logger.verifyEquals(fastrefundBean.getTraceId(), RefundRequest.getTraceId(),
//                "验证RefundRequest表中TraceId字段与快速退款请求一致");
//        Logger.verifyEquals(fastrefundBean.getAppId(), RefundRequest.getAppId(), "验证RefundRequest表中AppId字段与快速退款请求一致");
//        Logger.verifyEquals(aqb.getPayType(), RefundRequest.getPayType(), "验证RefundRequest表中PayType字段与收单请求一致");
//        Logger.verifyEquals(0, RefundRequest.getRefundAmount().compareTo(new BigDecimal(aqb.getPayPrice())),
//                "验证RefundRequest表中RefundAmount字段与收单请求一致");
//        Logger.verifyEquals(aqb.getCurrency(), RefundRequest.getCurrencyType(),
//                "验证RefundRequest表中CurrencyType字段与收单请求一致");
//        Logger.verifyEquals(9, RefundRequest.getApproveStatus(), "验证RefundRequest表中ApproveStatus字段为9：快速退款");
//        Logger.verifyEquals(fastrefundBean.getTradeType(), RefundRequest.getTradeType(),
//                "验证RefundRequest表中TradeType字段与收单请求一致");
//        Logger.verifyEquals(ppPayment.getInstitutionPaymentId(), RefundRequest.getInstPaymentId(),
//                "验证RefundRequest表中InstPaymentId字段与表PPPayment中一致");
//        //TODO 此字段状态受限发货服务是否获取到此退货请求如有延时可能为0
////        Logger.verifyEquals(-1, RefundRequest.getRefundStatus(), "验证RefundRequest表中RefundStatus字段为-1");
//
//        Logger.comment("验证数据表PP_CompensateProcessInfo（发货补偿信息）");
//        PPCompensateProcessInfo ppCompensateProcessInfo =
//                new PaymentDefaultWapper().selectPPCompensateProcessInfoByCorrelateIdAndCompensateType(
//                        paymentId, 1).get(0);
//        Logger.verifyEquals("1", ppCompensateProcessInfo.getAppId(), "验证PP_CompensateProcessInfo表中AppId字段为1");
//        Logger.verifyEquals("Refund", ppCompensateProcessInfo.getMethodName(),
//                "验证PP_CompensateProcessInfo表中MethodName字段为Refund");
//        Logger.verifyEquals(1, ppCompensateProcessInfo.getCompensateType(),
//                "验证PP_CompensateProcessInfo表中CompensateType字段为1:退款");
//    }
//}
